function replaceIdByName() {
	$(".get-fb-name").each(function(index, domEle) {
		var link = "/" + $(this).html();
		FB.api(link, function(response) {
			// Update the names
			$(domEle).html(response.name);
			$(domEle).show();
		});
	});
}

function replaceIdByPic() {
	$(".get-fb-pic").each(function(index, domEle) {
			if ($(this).html().charAt(0) != '<')
			{
				$(domEle).html("<img src='https://graph.facebook.com/" + $(this).html() + "/picture'/>");
				$(domEle).show();
			}
	});
	$(".get-fb-pic-normal").each(function(index, domEle) {
			$(domEle).html("<img src='https://graph.facebook.com/" + $(this).html() + "/picture?type=normal'>");
			$(domEle).show();
	});
	$(".get-fb-pic-large").each(function(index, domEle) {
			$(domEle).html("<img src='https://graph.facebook.com/" + $(this).html() + "/picture?type=large'>");
			$(domEle).show();
	});
}

function resize(element, size){
		element.hide();
		console.log("resized");
		var height = element.height();
		var width = element.width();
		if(height > width){
			element.css('height', size + 'px');
			element.css('width', '');
			element.css('margin-top', 0);
			if(element.height() < size){
				element.css('margin-top', ((size - element.height()) / 2));
			}
			
		}
		else{
			element.css('width', size + 'px');
			element.css('height', '');
			element.css('margin-top', 0);
			if(element.height() < size){
				element.css('margin-top', ((size - element.height()) / 2));
			}
		}
		element.show();
}

function resizePictures() {
	$(".resize-100").each(function(index, domEle) {
		resize($(this), 100);
	});
	
	$(".resize-150").each(function(index, domEle) {
		resize($(this), 150);
	});
	
	$(".resize-200").each(function(index, domEle) {
		resize($(this), 200);
	});
}

function initiateFeedbackform()
{
	$(function(){
	 $('#contactable').contactable({
	  subject: 'A Feedback Message for The Trove',
	  url : 'home/send_email',
	 });
	});
}



window.onload = function(){
	initiateFeedbackform();
	replaceIdByName();
	replaceIdByPic();
	resizePictures();
}

